var height = $(window).height();
$("#mainApp").height(height);	
var vue = new Vue({
	   el: '#app',
	   data: {
		  unitOpen : true,
	      isCollapse: false,
	      dialogAdd : false,
	      userId : '',
	      user : {
	    	  passWord : '',
	    	  repeatPassword : '',
	    	  id : ''
	      }
	   },
	   methods:{
		  // 加载新页面
		  openTab(targetName) {
			  // 该变DIV块内容
			  $.get(COMMON_URL.URL+targetName,function(data){
				 $('#mainApp').html(data);
			  });
	      },
	      logout(){
	    	 $.get(COMMON_URL.URL+"logout",function(){
	    		 window.location.href = COMMON_URL.URL+"login";
	    	 });
	      },
 		  updatePassword() {
	    	this.dialogAdd = true;
	      },
	      submitForm(formName){
	    	 
	    	  this.$refs[formName].validate((valid) =>{
	    		  if(valid){
	    			  this.user.id = $('#userInfoId').text();
	    			  
	    			  var value = this.user;
	    			  
	    			  var da = this;
	    			  
	    			  if(this.user.passWord == this.user.repeatPassword){
	    				  
	    				  $.ajax({
		    				  url : COMMON_URL.URL+'/userMessage/updateUserPasswordByself',
		    				  dataType : 'json',
		      				  type : 'post',
		      				  contentType: "application/json",
		      				  data : JSON.stringify(value),
		      				  success : function(data){
		      					  
		      					  if(data.ok){
		      						 da.dialogAdd = false;
		      						 swal('更新成功了','','success');
		      						 da.logout();
		      					  }else{
		      						swal('更新不成功：'+data.msg,'','warning');
		      					  }
		      					  
		      				  },
		      				  error : function(data){
		      					  swal('更新失败','','error');
		      				  }
		    				  
		    			  });
	    			  }else{
	    				  swal('两次密码不一致','','warning');
	    				  return;
	    			  }
	    		  }
	    		  
	    	  });
	    	  
	      },
	      resetForm(formName) {
	          this.$refs[formName].resetFields();
	        }
	   }
	});
	
	vue.openTab('wareHouseController/goodsTrade');